home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / support-files / mysql.server < prev    next >
Encoding:
Text File  |  2003-01-22  |  4.9 KB  |  183 lines  |  [TEXT/ttxt]

  1. #!/bin/sh
  2. # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
  3. # This file is public domain and comes with NO WARRANTY of any kind
  4.  
  5. # MySQL daemon start/stop script.
  6.  
  7. # Usually this is put in /etc/init.d (at least on machines SYSV R4 based
  8. # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
  9. # When this is done the mysql server will be started when the machine is
  10. # started and shut down when the systems goes down.
  11.  
  12. # Comments to support chkconfig on RedHat Linux
  13. # chkconfig: 2345 90 90
  14. # description: A very fast and reliable SQL database engine.
  15.  
  16. # Comments to support LSB init script conventions
  17. ### BEGIN INIT INFO
  18. # Provides: mysql
  19. # Required-Start: $local_fs $network $remote_fs
  20. # Required-Stop: $local_fs $network $remote_fs
  21. # Default-Start:  3 5
  22. # Default-Stop: 3 5
  23. # Short-Description: start and stop MySQL
  24. # Description: MySQL is a very fast and reliable SQL database engine.
  25. ### END INIT INFO
  26.  
  27. # If you install MySQL on some other places than /usr/local/mysql, then you
  28. # have to do one of the following things for this script to work:
  29. #
  30. # - Run this script from within the MySQL installation directory
  31. # - Create a /etc/my.cnf file with the following information:
  32. #   [mysqld]
  33. #   basedir=<path-to-mysql-installation-directory>
  34. # - Add the above to any other configuration file (for example ~/.my.ini)
  35. #   and copy my_print_defaults to /usr/bin
  36. # - Add the path to the mysql-installation-directory to the basedir variable
  37. #   below.
  38. #
  39. # If you want to affect other MySQL variables, you should make your changes
  40. # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
  41.  
  42. basedir=
  43.  
  44. # The following variables are only set for letting mysql.server find things.
  45.  
  46. # Set some defaults
  47. datadir=/usr/local/mysql/data
  48. pid_file=
  49. if test -z "$basedir"
  50. then
  51.   basedir=/usr/local/mysql
  52.   bindir=./bin
  53. else
  54.   bindir="$basedir/bin"
  55. fi
  56.  
  57. PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
  58. export PATH
  59.  
  60. if test -z "$pid_file"
  61. then
  62.   pid_file=$datadir/`/bin/hostname`.pid
  63. else
  64.   case "$pid_file" in
  65.     /* ) ;;
  66.     * )  pid_file="$datadir/$pid_file" ;;
  67.   esac
  68. fi
  69.  
  70. mode=$1    # start or stop
  71.  
  72. parse_arguments() {
  73.   for arg do
  74.     case "$arg" in
  75.       --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  76.       --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  77.       --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
  78.     esac
  79.   done
  80. }
  81.  
  82. # Get arguments from the my.cnf file,
  83. # groups [mysqld] [mysql_server] and [mysql.server]
  84. if test -x ./bin/my_print_defaults
  85. then
  86.   print_defaults="./bin/my_print_defaults"
  87. elif test -x $bindir/my_print_defaults
  88. then
  89.   print_defaults="$bindir/my_print_defaults"
  90. elif test -x $bindir/mysql_print_defaults
  91. then
  92.   print_defaults="$bindir/mysql_print_defaults"
  93. else
  94.   # Try to find basedir in /etc/my.cnf
  95.   conf=/etc/my.cnf
  96.   print_defaults=
  97.   if test -r $conf
  98.   then
  99.     subpat='^[^=]*basedir[^=]*=\(.*\)$'
  100.     dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
  101.     for d in $dirs
  102.     do
  103.       d=`echo $d | sed -e 's/[     ]//g'`
  104.       if test -x "$d/bin/my_print_defaults"
  105.       then
  106.         print_defaults="$d/bin/my_print_defaults"
  107.         break
  108.       fi
  109.       if test -x "$d/bin/mysql_print_defaults"
  110.       then
  111.         print_defaults="$d/bin/mysql_print_defaults"
  112.         break
  113.       fi
  114.     done
  115.   fi
  116.  
  117.   # Hope it's in the PATH ... but I doubt it
  118.   test -z "$print_defaults" && print_defaults="my_print_defaults"
  119. fi
  120.  
  121. parse_arguments `$print_defaults mysqld mysql_server mysql.server`
  122.  
  123. # Safeguard (relative paths, core dumps..)
  124. cd $basedir
  125.  
  126. case "$mode" in
  127.   'start')
  128.     # Start daemon
  129.  
  130.     if test -x $bindir/safe_mysqld
  131.     then
  132.       # Give extra arguments to mysqld with the my.cnf file. This script may
  133.       # be overwritten at next upgrade.
  134.       $bindir/safe_mysqld --datadir=$datadir --pid-file=$pid_file &
  135.       # Make lock for RedHat / SuSE
  136.       if test -w /var/lock/subsys
  137.       then
  138.         touch /var/lock/subsys/mysql
  139.       fi
  140.     else
  141.       echo "Can't execute $bindir/safe_mysqld from dir $basedir"
  142.     fi
  143.     ;;
  144.  
  145.   'stop')
  146.     # Stop daemon. We use a signal here to avoid having to know the
  147.     # root password.
  148.     if test -s "$pid_file"
  149.     then
  150.       mysqld_pid=`cat $pid_file`
  151.       echo "Killing mysqld with pid $mysqld_pid"
  152.       kill $mysqld_pid
  153.       # mysqld should remove the pid_file when it exits, so wait for it.
  154.  
  155.       sleep 1
  156.       while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ]
  157.       do
  158.         [ -z "$flags" ] && echo "Wait for mysqld to exit\c" || echo ".\c"
  159.         flags=a$flags
  160.         sleep 1
  161.       done
  162.       if [ -s $pid_file ]
  163.          then echo " gave up waiting!"
  164.       elif [ -n "$flags" ]
  165.          then echo " done"
  166.       fi
  167.       # delete lock for RedHat / SuSE
  168.       if test -f /var/lock/subsys/mysql
  169.       then
  170.         rm /var/lock/subsys/mysql
  171.       fi
  172.     else
  173.       echo "No mysqld pid file found. Looked for $pid_file."
  174.     fi
  175.     ;;
  176.  
  177.   *)
  178.     # usage
  179.     echo "usage: $0 start|stop"
  180.     exit 1
  181.     ;;
  182. esac
  183.